package com.zmn.oms.dubbo.impl.statistics;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.common.dro.statistics.UserOrderWarrantyStatDRO;
import com.zmn.oms.dubbo.interfaces.statistics.StatOrderWarrantyRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.zmn.business.interfaces.statistics.StatOrderWarrantyBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 类描述：用户订单保修状态统计
 *
 * @author liuyufan
 * @date 2021/12/6
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 8000, retries = 0, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class StatOrderWarrantyRemoteServiceImpl implements StatOrderWarrantyRemoteService {

    @Autowired
    private StatOrderWarrantyBService statOrderWarrantyBService;

    @Override
    public ResponseDTO<UserOrderWarrantyStatDRO> getUserOrderWarrantyStatByPhone(String phone) {
        try {
            UserOrderWarrantyStatDRO userWarrantyOrderStatByPhone = statOrderWarrantyBService.getUserWarrantyOrderStatByPhone(phone);
            return ResponseDTO.success(userWarrantyOrderStatByPhone);
        } catch (Exception e) {
            log.info("用户（手机号）订单保修状态统计异常{}",e.getMessage());
            return ResponseDTO.fail(e.getMessage());
        }
    }

    @Override
    public ResponseDTO<Long> countInWarrantyOrderByUserIdList(@NotNull(message = "用户ID列表不能为空") List<Long> userIdList) {
        try {
            Long count = statOrderWarrantyBService.countInWarrantyOrderByUserIdList(userIdList);
            return ResponseDTO.success(count);
        } catch (Exception e) {
            log.info("用户ID订单保修状态统计异常{}",e.getMessage());
            return ResponseDTO.fail(e.getMessage());
        }
    }


}
